<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <link href="css/primer.css" rel="stylesheet" />
    <link rel="stylesheet" href="css/basic.css" />
    <script src="http://cdn.staticfile.org/jquery/2.0.0/jquery.min.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.js"></script>
    <script src="Js/mask.js"></script>
    <script src="Js/md5.js"></script>

    <title>EZBabyCTF-team</title>
    <style>
        .team {
            width: 1024px;
            position: absolute;
            left: 50%;
            transform: translateX(-50%);
            text-align: center;
            font-size: large;
            font-weight: bold;
        }

        .Box-row {
            position: relative;
            height: 8vh;
            text-align: left;
            padding-left: 20%;
        }

        #ldicon {
            position: absolute;
            top: 75px;
            left: 15%;
        }

        #scoreboard {
            z-index: 5;
            height: 160px;
            position: absolute;
            top: 50px;
            right: 3%;
            color: var(--color-scale-yellow-3);
            text-align: center;
            background-color: rgba(0, 0, 0, 0.826);
            font: bold 100px arial, verdana;
        }

        #settm {
            position: absolute;
            top: 35px;
            right: -15%;
            display: none;
        }

        #rmteam:hover {
            background-color: var(--color-scale-red-4);
        }
    </style>
</head>

<body style="position: relative;">

    <div class="Header" style="background-color: rgba(0, 0, 0, 0.826)">
        <div class="Header-item m-auto">
            <span id="Head">EZBabyCTF队伍</span>
        </div>
        <div class="Header-item m-3">
            <span class="Header-link" id="tonotif">通知 </span>
        </div>
        <div class="Header-item m-3">
            <span class="Header-link" id="returnindex">返回首页</span>
        </div>
    </div>
    <div class="marsk-container"></div>

    <div class="Box anim-fade-in team" id="memberlist" style="position: relative;">
        <button class="btn-mktg btn-primary-mktg mr-3" id="settm" type="button">管理我的战队</button>
        <div class="border rounded-1 color-shadow-medium p-4" id="scoreboard"></div>
        <svg id="ldicon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24">
            <path
                d="M12 2.5a5.25 5.25 0 00-2.519 9.857 9.005 9.005 0 00-6.477 8.37.75.75 0 00.727.773H20.27a.75.75 0 00.727-.772 9.005 9.005 0 00-6.477-8.37A5.25 5.25 0 0012 2.5z">
            </path>
        </svg>
        <div class="Box-header" id="publishpl">战队</div>


    </div>

    <div class="popwindow" id="setttings">
        <div class="Box Box--overlay d-flex flex-column anim-fade-in fast" style="width: 600px;">
            <div class="Box-header">
                <button class="Box-btn-octicon btn-octicon float-right" type="button" onclick="closesign()">
                    <svg class="octicon octicon-x" viewBox="0 0 12 16" version="1.1" width="12" height="16">
                        <path fill-rule="evenodd"
                            d="M7.48 8l3.75 3.75-1.48 1.48L6 9.48l-3.75 3.75-1.48-1.48L4.52 8 .77 4.25l1.48-1.48L6 6.52l3.75-3.75 1.48 1.48L7.48 8z">
                        </path>
                    </svg>
                </button>
                <h3 class="Box-title">EZBabyCTF战队管理</h3>
            </div>
            <div class="Box-row"><strong>你是打算？</strong> </div>
            <div class="Box-footer" id="reassure">
                <button type="button" class="btn btn-block" id="addnm">我要邀请人</button>
                <button type="button" class="btn btn-block" id="kickass">我要踢人</button>
                <button type="button" class="btn btn-block" id="rmteam">解散我的战队</button>
            </div>
        </div>
    </div>
    <script>
        $(document).ready(function () {
            if ($.cookie("salt") == undefined) {
                window.alert("error 3");
                window.location.href = "index.html";
            }
            else {
                var id = $.cookie("salt").substring(0, 32);
                $.ajax({
                    url: "team.php",
                    type: "GET",
                    async: false,
                    dataType: "json",
                    data: {
                        id: id
                    },
                    success: function (response) {
                        console.log(response);
                        publish(response);
                    },
                    error: function () {
                        window.alert("error:1");
                    }
                })

            }
            $("#returnindex").click(function () {
                window.location.href = "index.html";
            })
            $("#tonotif").click(function () {
                window.location.href = "notifications.html";
            })
            $("#settm").click(function () {
                $(".popwindow").show();
                $(".marsk-container").show();
            })
            $("#addnm").click(function () {
                var newpl = $("#reassure");
                newpl.find("button").css("display", "none");
                newpl.append("<div><strong>请输入您要邀请的人的用户名(多人请用空格分开)</strong> </div>");
                newpl.append("<input type='text' class='form-control' style='width: 95%; margin: 2vh' id='nmtoadd' />");
                newpl.append("<button type='button' class='btn btn-block' onclick='yestoaddnm()'>确定</button>");
                $("#nmtoadd").keypress(function (event) {
                    if (
                        event.keyCode == 13) {
                        yestoaddnm();
                    }
                });
            })
            $("#kickass").click(function () {
                var newpl = $("#reassure");
                newpl.find("button").css("display", "none");
                newpl.append("<div><strong>请输入您要踢的人的用户名(多人请用空格分开)</strong> </div>");
                newpl.append("<input type='text' class='form-control' style='width: 95%; margin: 2vh' id='nmtorm' />");
                newpl.append("<button type='button' class='btn btn-block' onclick='yestormnm()'>确定</button>");
                $("#nmtorm").keypress(function (event) {
                    if (
                        event.keyCode == 13) {
                        yestormnm();
                    }
                });
            })
            $("#rmteam").click(function () {
                var newpl = $("#reassure");
                newpl.find("button").css("display", "none");
                newpl.append("<div><strong>确定要解散队伍？</strong> </div>");
                newpl.append("<button type='button' class='btn btn-block' onclick='yestodel()'>确定</button>");
                newpl.append("<button type='button' class='btn btn-block' onclick='closesign()'>取消</button>");
            })
        })
        function publish(response) {
            if (response[0] == '__ADMIN__') {
                $("#publishpl").text("亲爱的你是管理员没有战队耶");
                $("#scoreboard").hide();
                $("#memberlist").append("<div class=Box-row> 管理员并没有管理队伍的权限嘎嘎嘎！</div>");
                return;
            }
            else if (response[0] == '__NONE__') {
                $("#publishpl").text("亲爱的你目前还没有战队耶");
                $("#scoreboard").hide();
                $("#memberlist").append("<div class=Box-row>你是怎么进到这个页面的，很怪</div>");
                return;
            }
            else {
                $("#publishpl").text(response[0]);
                $("#scoreboard").text(response[2]);
                for (let i = 3; i < response.length; i++) {
                    $("#memberlist").append("<div class=Box-row>" + response[i] + "</div>")
                }
                if (response[1] == 'captain') {
                    $("#settm").show();
                }
            }
        }
        function yestoaddnm() {
            var id = $.cookie("salt").substring(0, 32);
            var teamnam = $("#publishpl").text();
            var torm = $("#nmtoadd").val();
            var text = torm.trim().split(' ');
            for (let i = 0; i < text.length; i++) {
                name = text[i];
                if (name == ' ' || name == '') {
                    continue;
                }
                $.ajax({
                    url: "idtoname.php",
                    type: "GET",
                    async: false,
                    data: {
                        id: id,
                    },
                    success: function (cpname) {
                        $.ajax({
                            url: "invitemember.php",
                            type: "GET",
                            data: {
                                tname: teamnam,
                                name: cpname,
                                inname: name
                            },
                            async: false,
                            success: function (response) {
                                if (response == 'done') {
                                    window.alert("邀请已发出");
                                } else {
                                    window.alert("怪了，出问题了，检查一下");
                                }
                            }
                        })
                    },
                    error: function () {
                        window.alert("error:1");
                    }
                })

            }
        }
        function yestormnm() {
            var id = $.cookie("salt").substring(0, 32);
            var teamnam = $("#publishpl").text();
            var torm = $("#nmtorm").val();

            var text = torm.trim().split(' ');
            for (let i = 0; i < text.length; i++) {
                name = text[i];
                if (name == ' ' || name == '') {
                    continue;
                }
                $.ajax({
                    url: "removemember.php",
                    type: "GET",
                    async: false,
                    data: {
                        tname: teamnam,
                        id: id,
                        rmname: name
                    },
                    success: function (response) {
                        if (response == 'done') {
                            $.ajax({
                                url: "message.php",
                                data: {
                                    from: id,
                                    msg: "队伍" + teamnam + "的队长把你移出了队伍qwq",
                                    to: hex_md5(name)
                                }
                            })
                            window.alert("移除成功！");
                        }
                        else if (response == 'NO') {
                            window.alert("不能移除自己，要不直接散伙？");
                        }
                        else {
                            window.alert("移除失败！:用户名为：" + name + "请检查一下");
                        }
                    },
                    error: function () {
                        window.alert("error:1");
                    }
                })

            }
        }
        function yestodel() {
            var id = $.cookie("salt").substring(0, 32);
            var teamnam = $("#publishpl").text();
            $.ajax({
                url: "removeteam.php",
                type: "GET",
                async: false,
                data: {
                    tname: teamnam,
                    id: id
                },
                success: function (response) {
                    if (response == 'done') {
                        window.alert("解散成功！");
                        window.location.href = "index.html";
                    } else {
                        window.alert("解散失败。");
                    }
                },
                error: function () {
                    window.alert("error:1");
                }
            })
        }
    </script>
</body>

</html>